import { IDictionaryItem } from "@/types";
import {
  FullAuditedAggregateRoot,
  PagedAndSortedResultRequestDto,
} from "../types";

export interface RoleDto {
  name: string;
  isDefault: boolean;
  isStatic: boolean;
  isPublic: boolean;
  id: string;
  extraProperties: Record<string, any>;
}

export interface GetRoleInputDto extends PagedAndSortedResultRequestDto {
  filter: string;
}

export interface SystemUserDto {
  id: string;
  tenantId: string;
  userName: string;
  name: string;
  surname: string;
  email: string;
  emailConfirmed: boolean;
  phoneNumber: string;
  phoneNumberConfirmed: boolean;
  isActive: boolean;
  roleNames: Array<string>;
  openId: string;
  gender: string;
  brithday: string;
  personnelIndustry: string;
  education: string;
  introduction: string;
  personalSignature: string;
  avatar: string;
  cardNumber: string;
  accountType: number;
  isStatic: false;
  nativePlace: string;
  nation: string;
  address: string;
  enterpriseId: string;
  regionCode: string;
  isDeleted: false;
  deleterId: string;
  deletionTime: string;
  lastModificationTime: string;
  lastModifierId: string;
  creationTime: string;
  creatorId: string;
  extraProperties: Record<string, any>;
  parentId: string;
  organizationId: string;
  organizationIds: Array<string>;
}

export interface ChangePasswordInputDto {
  oldPassword: string;
  newPassword: string;
}

export interface GetSystemUserInputDto extends PagedAndSortedResultRequestDto {
  Name: string;
  PhoneNumber: string;
  Email: string;
  Status: boolean;
}

export interface DataPermissionDto {
  enCode: string;
  name: string;
  description: string;
  sourceType: PermissionSourceType;
  sourceOptions: PermissionSourceOptions;
}

/**
 * 权限配置数据来源
 */
export enum PermissionSourceType {
  Organize = 1,
  Region = 2,
  Dictionary = 4,
  CustomList = 8,
  Remote = 16,
}

export interface PermissionSourceOptions {
  keyType: PermissionSourceKeyType;
  isTreeList?: boolean;
  options: Array<PermissionSourceOption>;
  extraFields: Array<PermissionSourceFieldItem>;
  url: string;
  headers: Record<string, string>;
  queryParams: Record<string, string>;
}

export enum PermissionSourceKeyType {
  String = 1,
  Guid = 2,
  Number = 4,
}

export interface PermissionSourceOption {
  name: string;
  value: string;
  extraProperties?: Record<string, string>;
  children?: Array<PermissionSourceOption>;
}

export interface PermissionSourceFieldItem {
  name: string;
  displayName: string;
}

export interface GetDataPermissionInputDto
  extends PagedAndSortedResultRequestDto {
  EnCode: string;
  Name: string;
}

export interface EnumItemDto {
  name: string;
  description: string;
  items: Array<EnumFieldItemDto>;
}

export interface EnumFieldItemDto {
  name: string;
  description: string;
  value: number;
}
export interface EnumsResultDto extends Record<string, EnumItemDto> {}

/**
 * 菜单类型
 */
export enum MenuType {
  Catalog = 1,
  Menu = 2,
}

export interface SystemMenuDto {
  extraProperties: Record<string, any>;
  id: string;
  creationTime: string;
  creatorId: string;
  lastModificationTime: string;
  lastModifierId: string;
  isDeleted: boolean;
  deleterId: string;
  deletionTime: string;
  groupName: string;
  parentId: string;
  permissionName: string;
  menuType: number;
  displayName: string;
  icon: string;
  url: string;
  sortIndex: number;
  status: boolean;
  remarks: string;
  permissionNames?: Array<string>;
}

/**
 * 所属部门信息
 */
export interface UserDepartmentDto {
  /**
   * 用户ID
   */
  userId: string;

  /**
   * 部门ID
   */
  depId: string;

  /**
   * 部门编码（PathCode)
   */
  depCode: string;

  /**
   * 部门名称
   */
  depName: string;
  /**
   * 部门名称
   */
  postName: string;
}

export interface SystemMenuTreeDto extends SystemMenuDto {
  children?: Array<SystemMenuTreeDto>;
}

export interface GetSystemMenuInputDto extends PagedAndSortedResultRequestDto {
  GroupName: string;
  Name: string;
  Status: boolean;
}

export interface DictionaryItemDto {
  id: string;
  creationTime: string;
  creatorId: string;
  lastModificationTime: string;
  lastModifierId: string;
  isDeleted: true;
  deleterId: string;
  deletionTime: string;
  parentId: string;
  moduleCode: string;
  code: string;
  name: string;
  description: string;
  icon: string;
  status: boolean;
  sortIndex: number;
  items?: Array<DictionaryValueDto>;
  extraProperties: Record<string, any>;
}

export interface DictionaryValueDto {
  id: string;
  itemId: string;
  description: string;
  name: string;
  value: string;
  status: boolean;
  sortIndex: number;
  extraProperties: Record<string, any>;
}

export interface GetDictionaryItemInputDto
  extends PagedAndSortedResultRequestDto {
  Key: string;
  ModuleCode: string;
  Status: boolean;
}

export interface GetConfigDefineInputDto
  extends PagedAndSortedResultRequestDto {
  Key: string;
  Category: string;
}

export interface ConfigDefineDto {
  id?: string;
  category: string;
  key: string;
  keyType: string;
  defaultValue?: string;
  keyDefaultValue?: string;
  keyName?: string;
  controlType?: string;
  controlProperty?: string;
  sortIndex: number;
}

export interface KeyConfigDefineDto {
  id: string;
  key: string;
  keyName: string;
  keyType: string;
  defaultValue: string;
  controlType: string;
  controlProperty: string;
  sortIndex: number;
}

export interface MultiConfigDefineDto {
  category: string;
  keyConfigs: Array<KeyConfigDefineDto>;
}

export interface GetConfigCategoryInputDto
  extends PagedAndSortedResultRequestDto {
  Key: string;
  Category: string;
  Level: number;
  ConfigType: number;
  Usage: number;
  Status: boolean;
}

export interface ConfigCategoryDto {
  id: string;
  creationTime: string;
  creatorId: string;
  lastModificationTime: string;
  lastModifierId: string;
  isDeleted: true;
  deleterId: string;
  deletionTime: string;
  name: string;
  level: number;
  moduleScope: Array<string>;
  configType: number;
  usage: number;
  status: boolean;
  defineFields: Array<ConfigDefineDto>;
  remarks: string;
  extraProperties: Record<string, any>;
}

export interface ConfigSettingDto {
  id: string;
  category: string;
  key: string;
  value: string;
  level: number;
  providerKey: string;
  moduleCode: string;
  usage: number;
}

export interface GetConfigSettingInputDto {
  Category: string;
  Level: number;
  ModuleCode: string;
  Usage: number;
}

export interface GetConfigValueInputDto {
  Category: string;
  ModuleCode: string;
  Key: string;
}

export interface SetConfigValueInputDto {
  category: string;
  moduleCode: string;
  key: string;
  value: string;
}

export interface ConfigDefineAndSettingDto {
  categoryId: string;
  categoryName: string;
  defineFields: Array<ConfigDefineDto>;
  values: Array<ConfigSettingValues>;
}

export interface ConfigSettingValues {
  moduleCode: string;
  level: number;
  values: Record<string, any>;
}

export interface SaveSettingsInputDto {
  category: string;
  moduleCode: string;
  level: number;
  configs: Record<string, any>;
}

export interface SaveAllSettingsInputDto {
  moduleCode: string;
  level: number;
  configs: Record<string, Record<string, any>>;
}

/**
 * 全局配置
 */
export interface AppConfigurationDto {
  /**
   * 当前登录用户
   */
  currentUser: SystemUserDto;
  /**
   * 当前所属部门列表（用户加入的部门岗位信息）
   */
  currentDepartments: Array<UserDepartmentDto>;

  /**
   * 当前用户可用菜单数据项
   */
  menuItems: Array<SystemMenuDto>;

  /**
   * 用户权限数据
   */
  auth: {
    grantedPolicies: Record<string, boolean>;
  };

  /**
   * 数据字典项
   */
  dictionaryItems: Array<IDictionaryItem>;
}

export interface PermissionDefinitionDto {
  name: string;
  displayName: string;
  isEnabled: true;
  properties: Record<string, any>;
  children?: Array<PermissionDefinitionDto>;
}

/**
 *
 */
export interface RegionDto {
  id?: string | null;
  parentId?: string;
  pathCode: string;
  level: RegionLevel;
  name: string;
  parentName: string;
  fullName: string;
  status: boolean;
  longitude: string;
  latitude: string;
  pinyin: string;
  extraProperties: Record<string, any>;
}

export interface RegionTreeDto extends RegionDto {
  children?: Array<RegionTreeDto>;
}

export interface GetRegionInputDto extends PagedAndSortedResultRequestDto {
  Name: string;
  ParentId: string;
  Level: RegionLevel;
  Code: string;
  Status: boolean;
}

/**
 * 行政区化级别
 */
export enum RegionLevel {
  Country = 1,
  Province = 2,
  City = 4,
  County = 8,
  Township = 16,
  Village = 32,
  Subset = 64,
}

export interface GetPermissionsInputDto {
  providerName: string;
  providerKey: string;
}

export interface SavePermissionsInputDto {
  providerName: string;
  providerKey: string;
  permissions: Array<{ name: string; isGranted: boolean }>;
}

export interface GetPermissionListResultDto {
  entityDisplayName: string;
  groups: Array<PermissionGroupDto>;
}

export interface PermissionGroupDto {
  name: string;
  displayName: string;
  displayNameKey: string;
  displayNameResource: string;
  permissions: Array<PermissionGrantInfoDto>;
}

export interface PermissionGrantInfoDto {
  name: string;
  displayName: string;
  isGranted: string;
  allowedProviders: Array<string>;
  grantedProviders: Array<{
    providerName: string;
    providerKey: string;
  }>;
}
